<template>
  <div class="t_box">
    <div class="search">
      <el-form ref="form" label-width="80px">
        <el-form-item label="文章类型">
          <el-input size="mini" v-model="articleType"></el-input>
          <el-button size="mini" type="primary">
            <i class="el-icon-search"></i>查询</el-button>
          <el-button size="mini" type="primary" @click="toCreate">
            <i class="el-icon-plus"></i>新增</el-button>
        </el-form-item>
      </el-form>
    </div>
    <el-table :data="typeList" size="mini" style="width: 96%; margin: auto;" height="400"
              cell-style="height: 30px; line-height: 30px;"
              header-cell-style="background: rgb(237, 239, 247);font-weight: normal;">
      <el-table-column label="序号" width="150">
        <template slot-scope="scope">{{scope.$index+1}}</template>
      </el-table-column>
      <el-table-column prop="typeName" label="类型名称">
      </el-table-column>
      <el-table-column prop="createDate" label="创建日期">
      </el-table-column>
      <el-table-column label="操作" width="300">
        <template slot-scope="scope">
          <el-button @click.native.prevent="updateType(scope.row.typeId)" type="text" size="small">
            编辑
          </el-button>
          <el-button @click.native.prevent="handleDelete(scope.row.typeId)" type="text" size="small">
            删除
          </el-button>
        </template>
      </el-table-column>
    </el-table>
    <div class="page">
      <el-pagination @size-change="handleSizeChange" @current-change="handleCurrentChange" :current-page="currentPage" :page-size="pageSize" layout=" prev, pager, next, sizes, jumper" :total="total">
      </el-pagination>
    </div>
  </div>
</template>
<script>
import request from "@/utils/request";
export default {
  name: 'articleType',
  data() {
    return {
      typeList: [],
      articleType: "",
      currentPage: 1, //默认第一页
      total: 0, //总条数
      pageSize: 10 //默认第一页展示10条
    }
  },
  mounted() {
    // 加载列表
    this.getArticleTypeList();
  },
  methods: {
    getArticleTypeList() {
      request({
        url: "/api/article/getArticleTypeList",
        method: "post",
        data: {}
      }).then(res => {
        console.log(res);
        if (res.msg === "查询成功") {
          this.typeList = res.list;
          this.total = this.typeList.length;
        }
      });
    },
    handleDelete(id) {

    },
    updateType(id) {

    },
    handleSizeChange(val) {
      this.pageSize = val;
    },
    handleCurrentChange(val) {
      this.currentPage = val;
    },
    toCreate() {
      // this.$router.push("createArticleType");
    },
  }
}

</script>
<style lang="scss">
.t_box {
  height: 100%;
  margin: 0 auto;

  .search {
    width: 30%;
    float: left;
  }

  .page {
    width: 30%;
    margin: auto;
    margin-top: 50px;
  }
}

</style>
